﻿var currentPage = 1; // 当前页
var pageSize = 18; // 每页显示多少条
var pageall = 0; // 总页数
var total = 0; // 总记录数
var type = 0;

$(document).ready(function() {
    ShowFollowList(currentPage);
});

function ShowFollowList(currentPage) {
    $("#divList").html(""); // 清空列表
    $("#divPage").html(""); // 清空分页
    var deptname = document.getElementById("umainclass").value;
    var deptid = "";
    if (deptname != "") {
        deptid = document.getElementById("utxdeptid").value;
    }
    var startTime = document.getElementById("StartTime").value;
    var EndTime = document.getElementById("EndTime").value;
    var UserName = document.getElementById("usubclass").value;
    type = 1;
    $("#divList").html("<img src=\"../images/loading.gif\" />"); // 清空列表 

    $.ajax({
        type: 'POST',
        url: '../Handler/HandlerCustomer.ashx',
        data: 'act=SelectCustomerOrFollowList&deptname=' + deptid + '&startTime=' + startTime + '&EndTime=' + EndTime + '&UserName=' + UserName + '&page=' + currentPage + '&pagesize=' + pageSize,
        timeout: '10000',
        error: function() {
            alert("系统繁忙，请稍后再试！");
        },
        success: function(json) {
            ShowFlowCallBack(json);
        }
    });
}

function ShowFlowCallBack(response) {
    var json = eval("(" + response + ")");
    var record = json.record;

    var page = json.page;
    currentPage = page.currentpage;
    pageall = parseInt(page.pageall);
    total = page.total;

    if (record == null || record.length == 0) {
        $("#divList").html("<font color='red'>&nbsp;系统内暂无您查询的信息!</font>");
        return;
    }

    $("#divList").html(""); // 显示列表
    var arr = [];
    arr.push("<table id='table2' width='100%' border='0' cellpadding='0' cellspacing='1' bgcolor='#a8c7ce'>");
    arr.push("<tr>");
    arr.push("<td height='25'  bgcolor='d3eaef' class='STYLE10'>");
    arr.push("序号");
    arr.push("</td>");
    arr.push("<td height='25' bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("待看时间</td>");
    arr.push("<td height='25' bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("客源跟进</td>");
    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("客户</td>");
    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("盘源编号</td>");

    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("楼盘栋阁</td>");

    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("面积</td>");



    arr.push("<td height='25'  bgcolor='d3eaef'  class='STYLE10'>");
    arr.push("人员</td>");
    arr.push("<td height='25' bgcolor='d3eaef' class='STYLE10'>");
    arr.push("部门</td>");
    arr.push("</tr>");

    for (var i = 0; i < record.length; i++) {
        if (i % 2 == 0)
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#FFFFFF' style='cursor: pointer;'  onclick=\"selectedTr('" + record[i].id + "')\">");
        else
            arr.push("<tr id='tr_" + record[i].id + "' bgcolor='#EEEDED' style='cursor: pointer;'  onclick=\"selectedTr('" + record[i].id + "')\">");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].id + "");
        arr.push("</td>");
        arr.push("<td height='25' class='STYLE10'>");
        arr.push("" + record[i].fdate + "</td>");
        arr.push("<td height='25' class='STYLE10' title='" + record[i].fcontent + "'>");
        var fcontent = record[i].fcontent;
        if (fcontent != "") {
            arr.push("" + fcontent.substring(0, 10) + "...</td>");
        } else {
            arr.push("" + record[i].fcontent + "</td>");
        }
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("<a href='#' onclick=\"openCustDetail('" + record[i].customerid + "')\">" + record[i].customer + "</a>");

        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("<a href='#' onclick=\"openDetail('" + record[i].fhousingid + "')\">" + record[i].fhousingid + "</a>");

        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].buildname + "</td>");///楼盘栋阁

        arr.push("<td height='25'  class='STYLE10'>");///面积
        arr.push("" + record[i].acreage + "</td>");
        
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].fuser + "</td>");
        arr.push("<td height='25'  class='STYLE10'>");
        arr.push("" + record[i].fdept + "</td>")
        arr.push("</tr>");
    }
    arr.push("</table>");

    $("#divList").html(arr.join('')); // 显示列表
    $("#divPage").html(""); // 清空
    if (pageall > 1) {
        var pageHtml = LexunJS.showPage(currentPage, pageall, "ShowFollowList");  // 分页
        $("#divPage").html(pageHtml);

    }
}
// 查看详情
function openDetail(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    var id_list = $("#hID_List").val();
    var url = "../PM/HousingDetail.aspx?id=" + id + "&id_list=" + escape(id_list);

    self.parent.closeTab('盘源详情');
    self.parent.addTab('盘源详情', url, 'icon-nav');
    //window.open("HousingDetail.aspx?id=" + id + "&id_list=" + escape(id_list), "target", LexunJS.openParams());
}

// 查看详情
function openCustDetail(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");

    var id_list = $("#hID_List").val();
    var url = "../CM/CustomerDetail.aspx?id=" + id;

    self.parent.closeTab('客源详情');
    self.parent.addTab('客源详情', url, 'icon-nav');
    //window.open("CustomerDetail.aspx?id=" + id + "&id_list=" + escape(id_list), "target", LexunJS.openParams());
}

// 选中某行
function selectedTr(id) {
    $("tr").removeClass("selected");
    $("#tr_" + id).addClass("selected");
}

//弹出窗口
function ShowDialogs(url, id) {
    var path = "../CM/" + url + "?id=" + id;
    var parameter = "客源跟进";
    var style = "dialogWidth:660px; dialogHeight:400px; status:0;scroll:1; help:0; resizable:1;Scrollbars=yes,Toolbar=no,Location=no,Direction=no,Resizeable=no";
    window.showModalDialog(path, parameter, style);

}
